package com.rmb.service.impl;

import com.rmb.mapper.ConsumeMapper;
import com.rmb.mart.entity.workbench.ConsumeTwo;
import com.rmb.service.ConsumeService;
import org.jacoco.agent.rt.internal_43f5073.core.internal.flow.IFrame;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * @ClassName ConsumeServiceImpl
 * @Description 趋势图
 * @Author lvshook
 * @Date 2021/1/22 10:47
 * @Version 1.0
 **/
@Service
public class ConsumeServiceImpl implements ConsumeService {

    @Autowired(required = false)
    private ConsumeMapper consumeMapper;

    /**
     * 循环次数
     */
    public static final float NUM = 12;

    public static final int SAN = 30;
    public static final int ONE = 30;
    /**
     *趋势图
     * @param consumeTwo
     * @return
     */
    @Override
    public Map getConsume(ConsumeTwo consumeTwo) {

        Map map = new HashMap(16);
        Calendar calendar = Calendar.getInstance();
        int a = calendar.get(Calendar.YEAR);



        if (consumeTwo.getData() == null){
            List<String> dataCome = new ArrayList();
            for (int i = 0; i < NUM; i++) {
                dataCome.add(a+"-"+(i+1)+"-01");
            }
            List<String> dataOver = new ArrayList();
            for (int i = 0; i < NUM; i++) {
                dataOver.add(a+"-"+(i+1)+"-28");
            }
            for (int i = 0; i < NUM; i++) {
                System.out.println(""+dataCome.get(i)+"-::"+dataOver.get(i)+"-::"+consumeTwo.getUid());
                Double consume = consumeMapper.getConsume(dataCome.get(i), dataOver.get(i), consumeTwo.getUid());
                if (consume==null){
                    map.put(a+"-"+(i+1),0);
                }else{
                    map.put(a+"-"+(i+1),consume);
                }

            }
        }
            List<String> dataCome = new ArrayList();
            for (int i = 0; i < NUM; i++) {
                dataCome.add(consumeTwo.getData()+"-"+(i+1)+"-01");
            }
            List<String> dataOver = new ArrayList();
            for (int i = 0; i < NUM; i++) {
                dataOver.add(consumeTwo.getData()+"-"+(i+1)+"-28");
            }
            for (int i = 0; i < dataOver.size(); i++) {
                System.out.println("看看："+dataCome.get(i)+"-::"+dataOver.get(i)+"-::"+consumeTwo.getUid());
                Double consume = consumeMapper.getConsume(dataCome.get(i), dataOver.get(i), consumeTwo.getUid());
                if (consume == null){
                    map.put(consumeTwo.getData()+"-"+(i+1),0);
                }else{
                    map.put(consumeTwo.getData()+"-"+(i+1),consume);
                }
            }




        return map;
    }
}
